{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "37f084bd-886d-4b72-ad64-cbdc8908f6b9",
   "metadata": {},
   "outputs": [],
   "source": [
    "from datetime import datetime"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "628610b8-5a6d-473d-bbf0-a9ad48faa295",
   "metadata": {},
   "outputs": [],
   "source": [
    "now = datetime.now()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "edccdc22-5b81-4c4b-b2ce-c6f44bbca3a7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2025-02-18 14:14:02.570902\n"
     ]
    }
   ],
   "source": [
    "print(now)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "a923e03e-e6e3-4b63-b59d-1ba6f6cb9834",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "datetime.datetime(2025, 2, 18, 14, 14, 2, 570902)"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "now"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "22edcec2-593f-4e49-9dfe-4f63e8d96bb2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'datetime.datetime'>\n"
     ]
    }
   ],
   "source": [
    "print(type(now))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "4a8e2301-5460-40e0-8ba5-88f96298ec7f",
   "metadata": {},
   "outputs": [],
   "source": [
    "dt =  datetime(2013, 4, 19,20,20)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "32c29193-23e1-437d-84ef-3dfe3a65b88b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2013-04-19 20:20:00\n"
     ]
    }
   ],
   "source": [
    "print(dt)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "3c9f3d1e-41bb-4187-9977-320b4d466d0d",
   "metadata": {},
   "outputs": [],
   "source": [
    " dt = datetime(2015, 4, 19, 12, 20)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "7ffad977-af7b-4bee-b034-df61dacf019b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1429417200.0"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dt.timestamp()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "e106d47c-05bc-4f67-ab24-cba1eff0671e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1739859242.570902"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nowstamp =  now.timestamp()\n",
    "nowstamp"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "88d51edd-ee6b-4cb1-95df-4a61e58d7b75",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2025-02-18 14:14:02.570902\n"
     ]
    }
   ],
   "source": [
    "print(datetime.fromtimestamp(nowstamp))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "14610320-863e-4657-8f58-5d6c43916dbf",
   "metadata": {},
   "outputs": [],
   "source": [
    " StrConVerstamp = datetime.strptime('2015-6-1 18:19:59', '%Y-%m-%d %H:%M:%S')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "55095a7e-3055-48eb-abb7-af95617eca71",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2015-06-01 18:19:59\n"
     ]
    }
   ],
   "source": [
    "print(StrConVerstamp)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "682a524f-9f9e-4fde-9143-2f8113b7c327",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'2025-02-18 14:14:02'"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "now.strftime('%Y-%m-%d %H:%M:%S')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "97351e33-a59d-4349-96bc-42bed8815866",
   "metadata": {},
   "outputs": [],
   "source": [
    "from datetime import timedelta"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "109008ad-bd0c-45a7-88d3-9dbb9ecafd3c",
   "metadata": {},
   "outputs": [],
   "source": [
    "now = datetime.now()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "a5f5443b-3713-4196-a58b-b98da2ccfdcc",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2025-02-19 00:28:29.643471\n"
     ]
    }
   ],
   "source": [
    "print(now + timedelta(hours=10))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "a240ccab-fbdd-4118-8ed6-ca1c1e1cfb91",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2025-02-17 14:28:29.643471\n"
     ]
    }
   ],
   "source": [
    "print(now - timedelta(days=1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "c2921ba5-b917-4dce-9ab0-b7492bb2e978",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "UTC+08:00\n"
     ]
    }
   ],
   "source": [
    "from datetime import datetime, timezone\n",
    "utc_8 = timezone(timedelta(hours=8))\n",
    "print(utc_8)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "71e7ba46-2d8f-4381-a5d6-0d6e7247ba14",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2025-02-18 15:15:54.354176\n"
     ]
    }
   ],
   "source": [
    "nows = datetime.now()\n",
    "print(nows)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "309d1c3b-0f23-43de-8fe6-7865bc643a4f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2025-02-18 15:15:54.354176+00:00\n"
     ]
    }
   ],
   "source": [
    "\n",
    "dt  = nows.replace(tzinfo=timezone.utc)\n",
    "print(dt)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "928e03c2-3993-4c21-b572-0b96a76a44b6",
   "metadata": {},
   "outputs": [],
   "source": [
    "utc_dt = datetime.utcnow().replace(tzinfo=timezone.utc)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "1b1032ee-b399-4aeb-87a1-ea29f3020d52",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2025-02-18 07:18:39.032947+00:00\n"
     ]
    }
   ],
   "source": [
    "print(utc_dt)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "7502681a-827a-4eba-af8b-85f74e69343d",
   "metadata": {},
   "outputs": [],
   "source": [
    "from datetime import timezone\n",
    "bjDt =utc_dt.astimezone(timezone(timedelta(hours=8)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "2cdbabb9-21b2-4592-bacf-ff0201283c15",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2025-02-18 07:18:39.032947+00:00\n"
     ]
    }
   ],
   "source": [
    "print(utc_dt)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "230d566f-eac8-46ca-9cff-ce94017bd902",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "UTC+08:00\n"
     ]
    }
   ],
   "source": [
    "print(timezone(timedelta(hours=8)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "57f4890c-126a-49d0-bcb6-96aa123dfd89",
   "metadata": {},
   "outputs": [],
   "source": [
    "bjDt = utc_dt.astimezone(timezone(timedelta(hours=8)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "id": "8ac1929d-c23f-4369-a18e-37faee9f39b9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2025-02-18 15:18:39.032947+08:00\n"
     ]
    }
   ],
   "source": [
    "print(bjDt)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b18a9f95-bba3-4510-ac0e-0361b4931549",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.21"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
